require "vivo/JPOS"

class Callbacks
	#
	# This callback should return some identifier used to group test runs together
	# on the main automation result report.  Typically this is a version/build number
	#
	def self.get_version
		version = UraniumQuery.get_run_version($run_id) if ($run_id)
	
		return version if (version && version != '')	
		return "R#{self.get_rws_revision}J#{self.get_jpos_revision}"
		return Time.new.strftime('%d-%m-%y') #just the current time stamp
	end

	def self.get_version_str
		return "RWS_#{self.get_rws_revision}, JPOS_#{self.get_jpos_revision}"
	end

	def self.get_rws_revision
=begin
		if (USE_ORACLE)
			cert = File.dirname(__FILE__) + "../vivo/Vivonet-CEG-DEV.pem"
			revision = nil
			
			Net::SSH.start(API_HOST, "ubuntu", :host_key => "ssh-rsa", :keys => [cert]) do |ssh|
				revision = ssh.exec!("svnversion /
			end
		else
=end
			rws_working_copy = "/Users/oshoghi/Desktop/server/"
			revision = `svnversion #{rws_working_copy}`
			return revision.match(/\d+/).to_a[0]
#end
	end

	def self.get_jpos_revision
		revision = JPOS::exec_shell_commands("svnversion /home/jpos/svn/jcard")
		return revision[0].match(/\d+/).to_a[0]
	end

	#
	# This callback will be invoked at the start of each automation run.  This is typically
	# used to install/deploy a build before actually starting the automation but it can be used
	# for any other purpose
	#
	def self.on_init
		RunDetails.set_fields({
			"Rest Rev" => self.get_rws_revision, 
			"JPOS Rev" => self.get_jpos_revision
		}, $run_id)
	end
end